package com.yourbatis.syntax;

import com.yourbatis.interpreter.Environment;

public class AssignmentStatement implements Statement {
    private final String name;
    private final Expression expression;

    public AssignmentStatement(String name, Expression expr) {
        this.name = name;
        this.expression = expr;
    }

    @Override
    public Object execute() {
//        Object value = expression.eval();
//        if (variables.containsKey(variableName)) {
//            Object oldValue = variables.get(variableName);
//            if (oldValue.getClass() != value.getClass()) {
//                throw new RuntimeException("Type mismatch for variable " + variableName);
//            }
//        }
//        variables.put(variableName, value);
        Object value = expression != null ? expression.eval() : null;
        Environment.define(name, value);
        return null;
    }


}
